﻿#region Using's

using System;
using System.IO;
using System.Windows.Markup;
using Domain1;
using DomainGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using XmlStorage;
using Domain1;

#endregion

namespace LightPersist
{
	[TestClass]
	public class UseCases
	{
		[TestInitialize]
		public void Setup() {}


		[TestMethod]
		public void StoreData()
		{
			var ctx = new Context("test1", GetDomain1());
			ctx.Storage = new InmemoryStorage();


			Control control1;
			using (var tr = ctx.BeginTransaction())
			{
				control1 = ctx.Create<Control>();

				control1.Width = 5;
				Assert.That(5 == control1.Width);

				tr.CommitTransaction();
			}
			Assert.That(5 == control1.Width);
		}

		[TestMethod]
		public void WorkingWithoutObjects()
		{
			var ctx = new Context("test1", GetDomain1());
			ctx.Storage = new InmemoryStorage();
			object obj1;
			using (var tr = ctx.BeginTransaction())
			{
				obj1 = ctx.Create("Control");
				var val1 = ctx.GetValue(obj1, "Width");
				ctx.SetValue(obj1, "Width", 7);
				tr.CommitTransaction();
			}
			Assert.IsTrue(ctx.GetValue(obj1, "Width").Equals(7));
		}

		public static DomainMetainfo GetDomain1()
		{
			var domain1 = (DomainMetainfo)XamlReader.Load(new FileStream("../../Domain1.xaml", FileMode.Open));


			domain1.Prepare();

			return domain1;
		}

	
	}
}